﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for CarInsuranceResultDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class CarInsuranceResultDB
    {
        public CarInsuranceResultDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarInsuranceResult carinsuranceresult)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarInsuranceResultInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            
            _sPara.Add("@CIVariableId", carinsuranceresult.CIVariableId);
            _sPara.Add("@ProviderCompanyId", carinsuranceresult.ProviderCompanyId);
            _sPara.Add("@CompanyLogoUrl", carinsuranceresult.CompanyLogoUrl);
            _sPara.Add("@InsurerName", carinsuranceresult.InsurerName);
            _sPara.Add("@AnnualPremium", carinsuranceresult.AnnualPremium);
            _sPara.Add("@ProposerExcess", carinsuranceresult.ProposerExcess);            
            _sPara.Add("@PolicyHolderAmt", carinsuranceresult.PolicyHolderAmt);
            _sPara.Add("@EachPassengerAmt", carinsuranceresult.EachPassengerAmt);
            _sPara.Add("@MedicalExpense", carinsuranceresult.MedicalExpense);
            _sPara.Add("@CashAllowance", carinsuranceresult.CashAllowance);
            _sPara.Add("@IsCarReplacement", carinsuranceresult.IsCarReplacement);
            _sPara.Add("@CarReplacementUrl", carinsuranceresult.CarReplacementUrl);
            _sPara.Add("@IsRoadTaxRenewal", carinsuranceresult.IsRoadTaxRenewal);
            _sPara.Add("@RoadTaxRenewalUrl", carinsuranceresult.RoadTaxRenewalUrl);
            _sPara.Add("@IsNCDProtectionIn", carinsuranceresult.IsNCDProtectionIn);
            _sPara.Add("@NCDProtectionInUrl", carinsuranceresult.NCDProtectionInUrl);
           
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public CarInsuranceResult GetCarInsuranceResultItem(Int64 CIVariableId)
        {
            CarInsuranceResult _carinsuranceresult = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "";

            SortedList _spara = new SortedList();
            _spara.Add("@CIVariableId", CIVariableId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carinsuranceresult = new CarInsuranceResult();
                    _carinsuranceresult = FillDataRecord(_dt, 0);
                }
            }
            return _carinsuranceresult;
        }

        private CarInsuranceResult FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarInsuranceResult myCarInsuranceResult = new CarInsuranceResult();
            myCarInsuranceResult.CIVariableId = Convert.ToInt64(myDataTable.Rows[RowId]["CIVariableId"].ToString());
            myCarInsuranceResult.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarInsuranceResult.CompanyLogoUrl = myDataTable.Rows[RowId]["CompanyLogoUrl"].ToString();
            myCarInsuranceResult.InsurerName = myDataTable.Rows[RowId]["InsurerName"].ToString();
            myCarInsuranceResult.AnnualPremium = myDataTable.Rows[RowId]["AnnualPremium"].ToString();
            myCarInsuranceResult.PolicyHolderAmt = myDataTable.Rows[RowId]["PolicyHolderAmt"].ToString();
            myCarInsuranceResult.EachPassengerAmt = myDataTable.Rows[RowId]["EachPassengerAmt"].ToString();
            myCarInsuranceResult.MedicalExpense = myDataTable.Rows[RowId]["MedicalExpense"].ToString();
            myCarInsuranceResult.CashAllowance = myDataTable.Rows[RowId]["CashAllowance"].ToString();
            myCarInsuranceResult.IsCarReplacement = myDataTable.Rows[RowId]["IsCarReplacement"].ToString();
            myCarInsuranceResult.CarReplacementUrl = myDataTable.Rows[RowId]["CarReplacementUrl"].ToString();
            myCarInsuranceResult.IsRoadTaxRenewal = myDataTable.Rows[RowId]["IsRoadTaxRenewal"].ToString();
            myCarInsuranceResult.RoadTaxRenewalUrl = myDataTable.Rows[RowId]["RoadTaxRenewalUrl"].ToString();
            myCarInsuranceResult.IsNCDProtectionIn = myDataTable.Rows[RowId]["IsNCDProtectionIn"].ToString();
            myCarInsuranceResult.NCDProtectionInUrl = myDataTable.Rows[RowId]["NCDProtectionInUrl"].ToString();
            return myCarInsuranceResult;
        }
    }
}
